package bTree.LeetCode;

public class 相同的树 {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        }

        if (p == null || q == null) {
            return false;
        }
        return check(p.left, q.left) && check(p.right, q.right);
    }
    boolean check(TreeNode p, TreeNode q){
        if (p == null && p == null) {
            return true;
        }

        if (p == null || p == null) {
            return false;
        }
        if(p.val!=q.val){
            return false;
        }
        return check(p.left, q.left) && check(p.right, q.right);
    }
}